<?php

namespace App\Imports;


use App\Models\administration\OfficeModel;
use Maatwebsite\Excel\Concerns\WithMultipleSheets;
use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToCollection;
use stdClass;
use App\Models\DeptModel;
use App\Models\AdminRoleModel;

class OfficeRecordImport implements ToCollection, WithMultipleSheets
{


    private $result;

    public function __construct() {
        $this->result = new stdClass;
    }

    public function collection(Collection $rows){
        $lines = [];
        $this->result->error = [];


        foreach ($rows as $k => $row) {
            if($k < 3) continue;

            $code = $row[2];

            $find = OfficeModel::where('code', $code)->first();

            if(!$find){
                $this->result->error[] = '行办公物品' . $row[3] .'不存在';
                continue;
            }

            $lines[] = [
                'office_id' => $find->id,
                'number' => $row[8],
                'reason' => $row[9],
                'date' => $row[10],
                'dept' => $row[11],
                'user' => $row[12],
                'remarks' => $row[13]
            ];
        }

        $this->result->lines = $lines;
    }

    public function sheets(): array {
        return [ 0 => $this];
    }

    public function get_result(){
        return $this->result;
    }


}
